#include <vector>
#include <set>

using namespace std;

class Solution {
public:
    vector<vector<int>> getSkyline(vector<vector<int>>& buildings) {
        multiset<int> set({0});
        multiset<pair<int, int>> line;
        vector<vector<int>> ans;
        for (vector<int> item : buildings) {
            line.insert({item[0], -item[2]});
            line.insert({item[1], item[2]});
        }
        int last[2] = {0, 0};
        for (pair<int, int> item : line) {
            if (item.second < 0) {
                set.insert(-item.second);
            } else {
                set.erase(set.find(item.second));
            }
            int max_height = *set.rbegin();
            if (max_height != last[1]) {
                last[1] = max_height;
                last[0] = item.first;
                ans.push_back({last[0], last[1]});
            }
        }
        return ans;
    }
};

int main() {
    vector<vector<int>> input = {{0, 2, 3}, {2, 5, 3}};
    Solution solution;
    solution.getSkyline(input);
    return 0;
}
